package MyCode.Swing.JFrameDemo;

import javax.swing.*;
import java.awt.*;

/**
 * JFrame类中的边界布局
 */
//1.继承JFrame
public class Gui2 extends JFrame {
    //2.定义组件
    JButton btn1, btn2, btn3, btn4, btn5;


    public Gui2() {
        //3.创建组件
        this.btn1 = new JButton("中部");
        this.btn2 = new JButton("北部");
        this.btn3 = new JButton("东部");
        this.btn4 = new JButton("南部");
        this.btn5 = new JButton("西部");

        //添加各个组件
        add(btn1, BorderLayout.CENTER);
        add(btn2, BorderLayout.NORTH);
        add(btn3, BorderLayout.EAST);
        add(btn4, BorderLayout.SOUTH);
        add(btn5, BorderLayout.WEST);

        //5.设置窗体属性
        setTitle("边界布局");
        setSize(300, 200);
        setLocationRelativeTo(this);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setVisible(true);

    }


    public static void main(String[] args){
        Gui2 g = new Gui2();
    }
}
